<?php

/**
 *  @FileComment            [品牌公共模型]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：BrandModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-10 16:34:19
 *  *
 */
class BrandModel extends Model {

        public $table = 'brand';
        public $validate = array(
            array('bname', 'nonull', '品牌名不能为空', 2, 3),
            array('sort', 'nonull', '排序不能为空', 2, 3),
            array('bname', 'maxlen:40', '品牌最大支持40个字符！', 2, 3),
            array('sort', 'maxlen:5', '排序最多5位数！', 2, 3),
            array('logo', 'nonull', '品牌logo必须上传', 2, 3)
        );
        public $auto = array(
            array('logo', '_up', 'method', 2, 3)
        );

        public function _up($value) {
                $path = '';
                foreach ($value as $v) {
                        $path = $v['path'];
                }
                return $path;
        }

        public function add_logo() {
                return $this->add();
        }

        public function get_all($where = NULL) {
                return $this->where($where)->all();
        }

        public function get_o_data($where) {
                return $this->where($where)->find();
        }

        public function get_data($tid = NULL) {
                return $this->where(array('type_tid' => $tid))->all();
        }

        public function get_one_data($bid) {
                return $this->where(array('bid' => $bid))->find();
        }

        public function edit_logo($bid) {
                return $this->where(array('bid' => $bid))->update();
        }

        public function del_data($bid) {
                $data = $this->where(array('bid' => $bid))->find();
                $img = $data['logo'];
                //删除logo图
                unlink($img);
                //删除数据库内容
                $this->where(array('bid' => $bid))->del();
                return true;
        }

}
